//
//  LBDownloaderModel.m
//  LBDownloader
//
//  Created by WuShiHai on 19/6/14.
//  Copyright (c) 2019 Lebbay All rights reserved.
//

#import "LBDownloaderModel.h"
#import <LBFoundation/LBFoundation.h>
#import "LBDownloaderModel+Util.h"

@implementation LBDownloaderModel

- (instancetype)init{
    if (self = [super init]) {
    }
    return self;
}

- (NSString *)filePath{
    return [[self folderPath] stringByAppendingPathComponent:[self fileName]];
}

- (NSString *)unzipFolderPath{
    
    //测试路径
    //TEST
    //    if (self.sourceUrl.length > 0){
    //        return [[Hybrid hybridPath] stringByAppendingFormat:@"/%@_%@.%@",self.pageName,self.version,self.sourceUrl.lastPathComponent.pathExtension];
    //    }
    //
    //    return nil;
    //end
    
    NSString *zipFileName = [self fileName];
    if (zipFileName.length > 0){
        zipFileName = [zipFileName stringByAppendingString:@"_unzip"];
        return [[self folderPath] stringByAppendingPathComponent:zipFileName];
    }
    return nil;
}

//压缩包是否解压完成标记文件
- (NSString *)unzipStateFilePath {
    return [[self folderPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"UnzipState_%@", [self fileName]]];
}

- (NSString *)debugInfoFilePath {
    return [[self folderPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"debug_%@", [self fileName]]];
}


/** 当前sourceType 对应的文件夹根路径 */
- (NSString *)root {
    return [LBDownloaderModel downloadPath];
}

- (NSString *)folderPath{
    return [[self root] stringByAppendingPathComponent:[[self identity] MD5]];
}

//- (NSString *)hashCodePath{
//    return [[self root] stringByAppendingPathComponent:[self urlHashCode]];
//}

- (NSString *)identity {
    return [self.url URLEncode];
}

//- (NSString *)urlHashCode {
//    //需要确定这里的hash属性 是否使用的对象内存地址hash 还是用的对象value
//    return [@([self identity].hash) stringValue];
//}

- (NSString *)fileName {
    return [self.url.lastPathComponent MD5];
}

@end
